package operatebag;

import people.User;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import mysqloperate.*;

public class changmima extends JFrame {
    JFrame jf;
    JLabel label;
    JTextField field;
    JButton b1;
    JButton B2;

    public changmima(User use){
        setTitle("修改用户密码");
        setBounds(500,200,400,500);
        setResizable(false);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        jf=this;
        setLayout(new FlowLayout());
        setVisible(true);
        label=new JLabel("输入修改后密码");
        field=new JTextField(13);
        b1=new JButton("确定");
        B2=new JButton("取消");
        add(label);
        add(field);
        add(b1);
        add(B2);
        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String changemima=field.getText();
                int n = JOptionPane.showConfirmDialog(null, "确认修改密码吗?", "确认对话框", JOptionPane.YES_NO_OPTION);
                if (n == JOptionPane.YES_OPTION) {

                    updateuserpassword gai=new updateuserpassword();

                    try {
                        gai.updata(use,changemima);
                        JOptionPane.showMessageDialog(new JFrame(),"成功");
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(new JFrame(),"修改失败");
                        throw new RuntimeException(ex);
                    }

                }
                else{
                    JOptionPane.showMessageDialog(new JFrame(),"已取消");
                }

            }
        });
        B2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jf.dispose();
            }
        });
    }
}
